package com.xmqian.app.project.ui;

import android.view.View;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.xmqian.app.project.common.apiadapter.DisplayCutoutUtils;
import com.xmqian.app.project.common.base.BaseMyActivity;
import com.xmqian.kotlinApp.R;
import com.xmqian.kotlinApp.databinding.ActivityGuideBinding;


/**
 * Desc： 引导界面
 * <p>
 * Author： xmqian
 * Email:xmqian93@163.com
 * Date: 2019/6/10 15:36\
 *
 * @link(com.xmqian.app.project.GuideFragment)
 */
public class GuideActivity extends BaseMyActivity {
    ViewPager mViewPager;
    //引导页图片
    private int[] GUIDE_IMAGE = new int[]{R.drawable.guide1, R.drawable.guide2, R.drawable.guide3};
    private GuideViewPageAdapter mAdapter;
    private ActivityGuideBinding binding;

    @Override
    protected View getLayoutView() {
        binding = ActivityGuideBinding.inflate(getLayoutInflater());
        return binding.getRoot();
    }

    @Override
    public void initView() {
        mViewPager = binding.viewPager;
        DisplayCutoutUtils.newInstance(this).setDisplayCutouMode(DisplayCutoutUtils.SHORT_EDGES);
        mAdapter = new GuideViewPageAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        initViewPagerItem();
    }

    @Override
    protected void initData() {

    }

    private void initViewPagerItem() {
        mViewPager.setOffscreenPageLimit(GUIDE_IMAGE.length);
        mAdapter.notifyDataSetChanged();
    }

    private class GuideViewPageAdapter extends FragmentPagerAdapter {
        @SuppressWarnings({"unchecked", "deprecation"})
        public GuideViewPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return com.xmqian.app.project.ui.GuideFragment.newInstance(GUIDE_IMAGE, position);
        }

        @Override
        public int getCount() {
            return GUIDE_IMAGE.length;
        }
    }
}

